/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package com.unwiredgrain.modeling.sscm.impl;

import com.unwiredgrain.modeling.sscm.InnerConnector;
import com.unwiredgrain.modeling.sscm.SSCMPackage;
import com.unwiredgrain.modeling.sscm.Wire;

import org.eclipse.emf.common.notify.Notification;

import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Wire</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link com.unwiredgrain.modeling.sscm.impl.WireImpl#getUser <em>User</em>}</li>
 *   <li>{@link com.unwiredgrain.modeling.sscm.impl.WireImpl#getProvider <em>Provider</em>}</li>
 *   <li>{@link com.unwiredgrain.modeling.sscm.impl.WireImpl#getUserIndex <em>User Index</em>}</li>
 *   <li>{@link com.unwiredgrain.modeling.sscm.impl.WireImpl#getProviderIndex <em>Provider Index</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class WireImpl extends BindingImpl implements Wire {
	/**
	 * The cached value of the '{@link #getUser() <em>User</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getUser()
	 * @generated
	 * @ordered
	 */
	protected InnerConnector user;

	/**
	 * The cached value of the '{@link #getProvider() <em>Provider</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getProvider()
	 * @generated
	 * @ordered
	 */
	protected InnerConnector provider;

	/**
	 * The default value of the '{@link #getUserIndex() <em>User Index</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getUserIndex()
	 * @generated
	 * @ordered
	 */
	protected static final int USER_INDEX_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getUserIndex() <em>User Index</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getUserIndex()
	 * @generated
	 * @ordered
	 */
	protected int userIndex = USER_INDEX_EDEFAULT;

	/**
	 * The default value of the '{@link #getProviderIndex() <em>Provider Index</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getProviderIndex()
	 * @generated
	 * @ordered
	 */
	protected static final int PROVIDER_INDEX_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getProviderIndex() <em>Provider Index</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getProviderIndex()
	 * @generated
	 * @ordered
	 */
	protected int providerIndex = PROVIDER_INDEX_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected WireImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return SSCMPackage.Literals.WIRE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public InnerConnector getUser() {
		if (user != null && user.eIsProxy()) {
			InternalEObject oldUser = (InternalEObject)user;
			user = (InnerConnector)eResolveProxy(oldUser);
			if (user != oldUser) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, SSCMPackage.WIRE__USER, oldUser, user));
			}
		}
		return user;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public InnerConnector basicGetUser() {
		return user;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetUser(InnerConnector newUser, NotificationChain msgs) {
		InnerConnector oldUser = user;
		user = newUser;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, SSCMPackage.WIRE__USER, oldUser, newUser);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setUser(InnerConnector newUser) {
		if (newUser != user) {
			NotificationChain msgs = null;
			if (user != null)
				msgs = ((InternalEObject)user).eInverseRemove(this, SSCMPackage.INNER_CONNECTOR__USE, InnerConnector.class, msgs);
			if (newUser != null)
				msgs = ((InternalEObject)newUser).eInverseAdd(this, SSCMPackage.INNER_CONNECTOR__USE, InnerConnector.class, msgs);
			msgs = basicSetUser(newUser, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SSCMPackage.WIRE__USER, newUser, newUser));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public InnerConnector getProvider() {
		if (provider != null && provider.eIsProxy()) {
			InternalEObject oldProvider = (InternalEObject)provider;
			provider = (InnerConnector)eResolveProxy(oldProvider);
			if (provider != oldProvider) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, SSCMPackage.WIRE__PROVIDER, oldProvider, provider));
			}
		}
		return provider;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public InnerConnector basicGetProvider() {
		return provider;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetProvider(InnerConnector newProvider, NotificationChain msgs) {
		InnerConnector oldProvider = provider;
		provider = newProvider;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, SSCMPackage.WIRE__PROVIDER, oldProvider, newProvider);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setProvider(InnerConnector newProvider) {
		if (newProvider != provider) {
			NotificationChain msgs = null;
			if (provider != null)
				msgs = ((InternalEObject)provider).eInverseRemove(this, SSCMPackage.INNER_CONNECTOR__PROVIDE, InnerConnector.class, msgs);
			if (newProvider != null)
				msgs = ((InternalEObject)newProvider).eInverseAdd(this, SSCMPackage.INNER_CONNECTOR__PROVIDE, InnerConnector.class, msgs);
			msgs = basicSetProvider(newProvider, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SSCMPackage.WIRE__PROVIDER, newProvider, newProvider));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getUserIndex() {
		return userIndex;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setUserIndex(int newUserIndex) {
		int oldUserIndex = userIndex;
		userIndex = newUserIndex;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SSCMPackage.WIRE__USER_INDEX, oldUserIndex, userIndex));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getProviderIndex() {
		return providerIndex;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setProviderIndex(int newProviderIndex) {
		int oldProviderIndex = providerIndex;
		providerIndex = newProviderIndex;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SSCMPackage.WIRE__PROVIDER_INDEX, oldProviderIndex, providerIndex));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case SSCMPackage.WIRE__USER:
				if (user != null)
					msgs = ((InternalEObject)user).eInverseRemove(this, SSCMPackage.INNER_CONNECTOR__USE, InnerConnector.class, msgs);
				return basicSetUser((InnerConnector)otherEnd, msgs);
			case SSCMPackage.WIRE__PROVIDER:
				if (provider != null)
					msgs = ((InternalEObject)provider).eInverseRemove(this, SSCMPackage.INNER_CONNECTOR__PROVIDE, InnerConnector.class, msgs);
				return basicSetProvider((InnerConnector)otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case SSCMPackage.WIRE__USER:
				return basicSetUser(null, msgs);
			case SSCMPackage.WIRE__PROVIDER:
				return basicSetProvider(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case SSCMPackage.WIRE__USER:
				if (resolve) return getUser();
				return basicGetUser();
			case SSCMPackage.WIRE__PROVIDER:
				if (resolve) return getProvider();
				return basicGetProvider();
			case SSCMPackage.WIRE__USER_INDEX:
				return getUserIndex();
			case SSCMPackage.WIRE__PROVIDER_INDEX:
				return getProviderIndex();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case SSCMPackage.WIRE__USER:
				setUser((InnerConnector)newValue);
				return;
			case SSCMPackage.WIRE__PROVIDER:
				setProvider((InnerConnector)newValue);
				return;
			case SSCMPackage.WIRE__USER_INDEX:
				setUserIndex((Integer)newValue);
				return;
			case SSCMPackage.WIRE__PROVIDER_INDEX:
				setProviderIndex((Integer)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case SSCMPackage.WIRE__USER:
				setUser((InnerConnector)null);
				return;
			case SSCMPackage.WIRE__PROVIDER:
				setProvider((InnerConnector)null);
				return;
			case SSCMPackage.WIRE__USER_INDEX:
				setUserIndex(USER_INDEX_EDEFAULT);
				return;
			case SSCMPackage.WIRE__PROVIDER_INDEX:
				setProviderIndex(PROVIDER_INDEX_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case SSCMPackage.WIRE__USER:
				return user != null;
			case SSCMPackage.WIRE__PROVIDER:
				return provider != null;
			case SSCMPackage.WIRE__USER_INDEX:
				return userIndex != USER_INDEX_EDEFAULT;
			case SSCMPackage.WIRE__PROVIDER_INDEX:
				return providerIndex != PROVIDER_INDEX_EDEFAULT;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (userIndex: ");
		result.append(userIndex);
		result.append(", providerIndex: ");
		result.append(providerIndex);
		result.append(')');
		return result.toString();
	}

} //WireImpl
